package cn.myplus.parserswagger;

import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.core.models.SwaggerParseResult;

public class ParserSwagger {

    public OpenAPI parse(String url) {
//        SwaggerParseResult result = new OpenAPIParser().readLocation("https://petstore3.swagger.io/api/v3/openapi.json", null, null);
        SwaggerParseResult result = new OpenAPIParser().readLocation(url, null, null);
        // or from a file
        //   SwaggerParseResult result = new OpenAPIParser().readLocation("./path/to/openapi.yaml", null, null);

        // the parsed POJO
        OpenAPI openAPI = result.getOpenAPI();

        if (result.getMessages() != null)
            result.getMessages().forEach(System.err::println); // validation errors and warnings

        if (openAPI != null) {
            System.out.printf("openAPI:", openAPI);
        }
        return openAPI;
    }
}
